<?php
/**
 * 路線図検索用関数<br />
 *
 * @package apamanshop
 * @author　SS永田
 * @copyright　
 */
class Rstobi_Model_RosenzuSearch extends Rstobi_Model_Base
{
    /**
     * 路線図検索用From句取得
     *
	 * @access	public
	 * @param   array
	 * @param	array ※参照渡し
	 * @return  string
     */
	public function getFromForRosenzusearch($params ,&$db_params)
	{

		//路線図駅CDをカンマ区切りにする
		$strStCode='';
		$cnt = 0;
		for ($i = 0; $i < count($params['stcode']); $i++)
		{
			if(!is_null($params['stcode'][$i]) && trim($params['stcode'][$i]) <> '')
			{
				// カンマの取得
				$strComma = $this->_model_rstobi_common->getPause($cnt,",");
				$db_params['strStCode_'.$i] = $params['stcode'][$i];

				$strStCode .= $strComma.' :strStCode_'.$i.' ';

				$cnt++;
			}
		}

		$strFrom  = ' from';
//		$strFrom .= ' (select';
//		$strFrom .= '      M03_ENSEN_CD';
//		$strFrom .= '     ,M03_EKI_CD';
//		$strFrom .= '  from';
//		$strFrom .= '      M03EKI';
//		$strFrom .= '  where';
//		$strFrom .= '      M03_ROSENZU_EKI_CD in ('.$strStCode.')) M03';
		
		// 2011/01/24 連絡駅対応
		$strFrom .= ' (select';
		$strFrom .= '     M03_ENSEN_CD';
		$strFrom .= '    ,M03_EKI_CD';
		$strFrom .= ' from';
		$strFrom .= '     M03EKI';
		$strFrom .= ' where';
		$strFrom .= '     M03_RENRAKU_EKI_CD in (select M03_RENRAKU_EKI_CD from M03EKI where M03_ROSENZU_EKI_CD in ('.$strStCode.'))';
		$strFrom .= ' union';
		$strFrom .= ' select';
		$strFrom .= '     M03_ENSEN_CD';
		$strFrom .= '    ,M03_EKI_CD';
		$strFrom .= ' from';
		$strFrom .= '     M03EKI';
		$strFrom .= ' where';
		$strFrom .= '     M03_ROSENZU_EKI_CD in ('.$strStCode.')) M03';
		$strFrom .= ' ,T03WEB_HEYA T03 ';

		return $strFrom;
	}

    /**
     * 路線図検索用Where句取得
     *
	 * @access	public
	 * @param   array
	 * @param	array ※参照渡し
	 * @return  string
     */
	public function getWhereForRosenzusearch($params ,&$db_params)
	{
		$strWhere  = ' where';

		// 沿線・駅CD
		$strWhere .= ' (   M03.M03_EKI_CD = T03.T03_EKI_CD01';
		$strWhere .= '  OR M03.M03_EKI_CD = T03.T03_EKI_CD02';
		$strWhere .= '  OR M03.M03_EKI_CD = T03.T03_EKI_CD03)';

		return $strWhere;
	}
}